<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增问题')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-dfQuestion-add" >
			<div class="form-group">
				<label class="col-sm-3 control-label">用户名称：</label>
				<div class="col-sm-8">
					<input id="userName" name="userName" class="form-control" type="text" th:value="${user.userName}" readonly>
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">用户id：</label>
				<div class="col-sm-8">
					<input id="userId" name="userId" class="form-control" type="hidden" th:value="${user.userId}">
				</div>
			</div>
			<div class="form-group" >
				<label class="col-sm-3 control-label">用户单位：</label>
				<div class="col-sm-8">
					<input id="userDept" name="userDept" class="form-control" type="text" th:value="${dept.deptName}" readonly>
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">用户单位id：</label>
				<div class="col-sm-8">
					<input id="userDeptId" name="userDeptId" class="form-control" type="hidden" th:value="${dept.deptId}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">联系方式：</label>
				<div class="col-sm-8">
					<input id="userPhone" name="userPhone" class="form-control" type="text" th:value="${user.phonenumber}" readonly>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="questionAnswer" name="questionAnswer" class="form-control" type="text" >
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">问题类型：</label>
				<div class="col-sm-8" style="padding-top: 3px;">
					<select name="questionType" class="form-control">
						<option value="2">处理</option>
						<option value="3">解释</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">问题版本号：</label>
				<div class="col-sm-8" >
					<select name="questionVersion" class="form-control" th:with="type=${@dict.getType('df_question_version')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
					</select>
				</div>
			</div>
			<!--<div class="form-group">-->
                <!--<label class="col-sm-3 control-label"></label>-->
				<!--<div class="col-sm-8" style="padding-top: 3px;">-->
					<!--<input type="checkbox" id="checkboxId" style="border: solid 1px #9d9d9d; background-color: #fff;"><span style="padding-left: 10px; font-size: 14px; color: #cc0000; position: relative; top: -2px;">已通过线下审核</span>-->
					<input id="questionState" name="questionState" class="form-control" type="hidden" value="0">
				<!--</div>-->
			<!--</div>-->
			<div class="form-group">
				<label class="col-sm-3 control-label">问题标题：</label>
				<div class="col-sm-8">
					<input id="questionTitle" name="questionTitle" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">内容描述：</label>
				<div class="col-sm-8">
					<textarea id="questionContent" name="questionContent" class="form-control" rows="5" style="resize:none;"></textarea>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-8">
					<input id="questionStart" name="questionStart" class="form-control" type="hidden" value="0">
				</div>
			</div>


			<div class="form-group">
				<label class="col-sm-3 control-label">上传附件：</label>
				<input type="file" accept="image/*" onchange="uploadFile()" id="fileUpload" multiple="multiple" style="display: none"/>
				<div class="col-sm-8">
					<!--<ul class="question_addfail_ul" id="lid">-->
						<!--<li><img id="img0" src=""><button class="question_delete"></button></li>-->

					<!--</ul>-->
					<ul id="lid"></ul>
					<ul>
						<li><button type="button" class="question_addfail"onclick="upload()"></button></li>
					</ul>

				</div>
			</div>

		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "question/dfQuestion"
        var prefis = ctx + "question/dfFile"
        var preFile = "http://211.149.205.33:18080/file/";
		$("#form-dfQuestion-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
        //判断复选框是否选中
		$("#checkboxId").click(function () {
            if ($("#checkboxId").is(':checked')){
                //如果选择赋值为1
				$("#questionState").val("1");
            }else {
                $("#questionState").val("0");
			}
        })

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-dfQuestion-add').serialize
                (),saveCallback);
            }
        }
        function saveCallback(result) {
            var question_id = result.data;
            addFile(question_id) //上传
        }
		function upload() {
            $("#fileUpload").click()
        }
        var arr =[];  //定义一个数组
        function uploadFile(){		 //
            var file = $("#fileUpload").get(0).files[0];
            if(file != undefined){
                var formData = new FormData();
                formData.append("files", file);
                $.ajax({
                    url:preFile+"mulitiupload",
                    type: "POST",
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function(resp) {
                        var model=new Object();
                        model.fileId =resp[0].fileid; //文件id
                        model.fileName =resp[0].name;//文件名称
                        var index = model.fileName.lastIndexOf(".");
                        var suffix = model.fileName.substring(index+1);
                        model.fileType =suffix; //文件类型
                        arr.push(model);
                        var downUrl="http://211.149.205.33:18080/file/down/"+model.fileId;
                        if(suffix=="png" || suffix=="jpg"){
                            $("#lid").append('<img src="'+preFile+"img/"+model.fileId+'" style="width: 66px;height: 66px" id="img0" >').append(" ");
                        }
                        if(suffix=="xls" || suffix=="xlsx"){
                            $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916001140350+'" style="width: 66px;height: 66px" id="img0"></a>').append(" ");
                        }
                        if(suffix=="docx"|| suffix=="doc"){
                            $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916001206935+'" style="width: 66px;height: 66px" id="img0" ></a>').append(" ");
                        }
                        if(suffix=="zip" || suffix=="rar"){
                            $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916001125877+'" style="width: 66px;height: 66px" id="img0" ></a>').append(" ");
                        }
                        if(suffix=="ppt" || suffix=="pptx"){
                            $("#lid").append('<a href="'+downUrl+'"><img src="'+preFile+"img/"+190916091106432+'" style="width: 66px;height: 66px" id="img0" ></a>').append(" ");
                        }
                    },
                    error: function(error) {
                        $.modal.alertWarning("附件上传失败。");
                    }
                });
            } else {
                $.modal.alertWarning("服务出现错误 。联系管理员 ");
            }
        };


        function addFile(question_id){
            $.ajax({
                url:prefis+"/saveFile",
                type: "POST",
                data: {questionId:question_id,array:JSON.stringify(arr)},
                dataType:"json",
                success: function(resp) {

                }
            });
        }

	</script>
</body>
</html>
